package com.juc.cyclicbarrier.cyclicbarrier7;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

public class MyService {
   /**
    * getNumberWaiting() 的作用是有几个线程已经到达屏障点
    * getParties()的作用是取得parties个数
    */
	
	CyclicBarrier cyclicBarrier = new CyclicBarrier(3, new Runnable() {
		
		@Override
		public void run() {
			
			System.out.println("   彻底结束了  " + System.currentTimeMillis());
		}
	});
	public void testMethod() {
		try {
			System.out.println(Thread.currentThread().getName() + " 准备！ " + System.currentTimeMillis() );
			if (Thread.currentThread().getName().equals("C")) {
				Thread.sleep(Integer.MAX_VALUE);
			}
			cyclicBarrier.await();
			System.out.println(Thread.currentThread().getName() + " 开始！ " + System.currentTimeMillis() );

		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (BrokenBarrierException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
